package org.tobuy.dao.proxy;

import java.util.ArrayList;
import java.util.List;

import org.tobuy.dao.IScoreDAO;
import org.tobuy.dao.impl.ScoreDAOImpl;
import org.tobuy.dbc.DatabaseConnection;
import org.tobuy.vo.Item;
import org.tobuy.vo.Score;
import org.tobuy.vo.User;

public class ScoreDAOProxy implements IScoreDAO{
	
	private DatabaseConnection dbc= null;
	private IScoreDAO dao = null; //problem?
	
	public ScoreDAOProxy(){
		try{
			this.dbc = new DatabaseConnection();
		}catch(Exception e){
			e.printStackTrace();
		}
		this.dao = new ScoreDAOImpl(dbc.getConnection());
	}

	public boolean addScore(Score score) throws Exception {
		boolean flag = false;
		try{
			flag = this.dao.addScore(score);
		}catch(Exception e){
			throw e;
		}finally{
			this.dbc.close();
		}
		return flag;
	}

	public List<Score> findBuyerScoreSet(User buyer) throws Exception {
		List<Score> scores = new ArrayList<Score>();
		try{
			scores = this.dao.findBuyerScoreSet(buyer);
		}catch(Exception e){
			throw e;
		}finally{
			this.dbc.close();
		}
		return scores;
	}

	public List<Score> findSellerScoreSet(User seller) throws Exception {
		List<Score> scores = new ArrayList<Score>();
		try{
			scores = this.dao.findSellerScoreSet(seller);
		}catch(Exception e){
			throw e;
		}finally{
			this.dbc.close();
		}
		return scores;
	}

	public List<Score> findItemScoreSet(Item item) throws Exception {
		List<Score> scores = new ArrayList<Score>();
		try{
			scores = this.dao.findItemScoreSet(item);
		}catch(Exception e){
			throw e;
		}finally{
			this.dbc.close();
		}
		return scores;
	}

}
